package leetcode;

import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-16 21:28
 **/
public class LeetCode203 {

    public ListNode removeElements(ListNode head, int val) {
        ListNode tou = new ListNode();
        tou.next = head;
        ListNode temp = tou;
        while (temp.next != null) {
            if (temp.next.val == val) {
                temp.next = temp.next.next;
            } else {
                temp = temp.next;
            }
        }
        return tou.next;
    }

    public static void main(String[] args) {
        LeetCode203 code = new LeetCode203();
        ListNode head = new ListNode();
        ListNode temp = head;
        for (int i = 0; i < 4; i++) {
            temp.next = new ListNode(7);
            temp = temp.next;
        }
        code.removeElements(head, 7);
    }


}

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}